<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateChatUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     *
     * @return void
     */
    public function up()
    {
        //用户联系人记录表
        Schema::create('chat_users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('sender')->unsigned()->comment('发送者id号')->nullable();
            $table->foreign('sender')->references('id')->on('employees')->onDelete('set null');
            $table->integer('receiver')->unsigned()->comment('接受者id号')->nullable();
            $table->foreign('receiver')->references('id')->on('employees')->onDelete('set null');
            $table->unique(['sender','receiver']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('chat_users');
    }
}
